#!/bin/sh

usage() {
    echo "Usage: $0 master <master_ip> <path_to_bind_chroot>"
    echo "       $0 agent  <master_ip> <authz_code>"
    echo "       $0 slave  <master_ip> <authz_code> <path_to_bind_chroot>"
}

    
if [ $# -lt 3 ]; then
    usage
    exit 1
else
    TYPE=$1
    MASTERIP=$2
    if [ $TYPE = "master" ]; then
        BIND_CHROOT=$3
        xdmaster $MASTERIP $BIND_CHROOT
    elif [ $TYPE = "agent" ]; then
        AUTHZCODE=$3 
        xdagent $MASTERIP $AUTHZCODE
    elif [ $TYPE = "slave" ]; then
        if [ $# -lt 4 ]; then
            usage
            exit 1
        fi
        AUTHZCODE=$3
        BIND_CHROOT=$4
        xdslave $MASTERIP $AUTHZCODE $BIND_CHROOT
    else
        usage
        exit 1
    fi
fi
